from appium import webdriver
from app_test.page.base_page import BasePage
from app_test.page.search.search_page import SearchPage
from utils.logger import logger
from utils.data_loader import DataLoader

# 加载配置文件caps.yml
data = DataLoader.load_case_data('app', 'config', 'caps.yml')
desire_caps = data['desireCaps']
ip = '127.0.0.1'
port = '4723'

class App(BasePage):
    """
    1. set the mobile initial configurations: desire_cap
    2. 初始化一个session
    3.
    """
    def start(self):
        if self.driver == None:
            try:
                self.driver = webdriver.Remote(f"http://{ip}:{port}/wd/hub", desire_caps)
                self.driver.implicitly_wait(10)
            except Exception as E:
                logger.info(E)
        else:
            self.driver.launch_app()
        return self

    def stop(self):
        self.driver.quit()

    def restart(self):
        self.driver.close_app()
        self.driver.launch_app()

    # def goto_main(self):
    #     # return to other class with the parameter: self.driver.
    #     return MainPage(self.driver)

    def goto_search(self):
            # 跳转到搜索页面
        print('跳转到搜索页面')
        return SearchPage(self.driver)


























